<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img
          class="logo-img"
          src="@/assets/image/icon.png"
          alt=""
        />
        <span>纪检监察信息化平台</span>
      </div>
      <div>
        <i class="el-icon-user-solid"></i>
        <p>{{level}}</p>
        <el-tooltip
          class="item"
          effect="dark"
          content="退出登录"
          placement="top"
          :open-delay="500"
        >
          <el-button
            type="danger"
            icon="el-icon-d-arrow-right"
            @click="logout"
            size="mini"
            circle
          ></el-button>
        </el-tooltip>
      </div>
    </el-header>
    <!-- 内容区域 -->
    <el-container class="section-container">
      <!-- 左侧导航边栏 -->
      <el-aside :width="isCollpase ? '65px' : '200px'">
        <div
          class="toggle-button"
          @click="toggleCollapse"
        >
          <i :class="isCollpase?'el-icon-s-unfold ':'el-icon-s-fold'"></i>
        </div>
        <!-- 侧边栏菜单 -->
        <el-menu
          background-color="#D6251F"
          text-color="#fff"
          active-text-color="#409eff"
          unique-opened
          :collapse="isCollpase"
          :collapse-transition="false"
          :router="true"
          :default-active="activePath"
        >
          <el-menu-item
            :index="item.id"
            v-for="item in menuList"
            :key="item.id"
            @click="saveNavState(item.id)"
          >
            <i :class="item.iconPath"></i>
            <span slot="title">{{item.name}}</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <!-- 右侧主体区域 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      // 用户信息
      level: '超级管理员',
      // 左侧菜单数据
      menuList: [
        {
          id: '/accuse/add',
          name: '新增检举',
          iconPath: 'el-icon-circle-plus'
        },
        {
          id: '/accuse/approve',
          name: '审批转办',
          iconPath: 'el-icon-s-check'
        },
        {
          id: '/accuse/records',
          name: '检举记录',
          iconPath: 'el-icon-s-order'
        },
        {
          id: '/accuse/user',
          name: '用户管理',
          iconPath: 'el-icon-s-custom'
        }
      ],
      // 是否折叠
      isCollpase: false,
      // 被激活的链接地址
      activePath: ''
    }
  },
  created() {
    this.getMenuList()
    this.activePath = this.$route.path
  },
  updated() {
    this.activePath = this.$route.path
  },
  methods: {
    logout() {
      this.$router.push('/login')
    },
    // 获取所有的菜单
    async getMenuList() {

    },
    // 点击按钮切换菜单的折叠与展开
    toggleCollapse() {
      this.isCollpase = !this.isCollpase
    },
    // 保存链接的激活状态，解决侧边栏高亮问题
    saveNavState() {
      this.activePath = this.$route.path
    }
  }
}
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background: #d6251f;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #e6e6e6;
  > div {
    display: flex;
    align-items: center;
    span {
      font-size: 20px;
      font-weight: 600;
      margin-left: 15px;
    }
    P {
      margin-left: 5px;
      margin-right: 30px;
      font-size: 14px;
    }
  }
}
.logo-img {
  width: 30px;
}
.el-aside {
  background-color: #d6251f;
  // 解决左侧菜单不能对齐的问题
  .el-menu {
    border-right: none;
    i {
      color: #ffffff;
    }
  }
}
.section-container {
  height: 0;
}
.el-main {
  overflow: hidden;
  box-sizing: border-box;
  background: linear-gradient(180deg, #b9dadf 0%, #f3fbfd 100%);
}
.toggle-button {
  background-color: #fc424d;
  line-height: 24px;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
  i {
    color: #ffffff;
    height: 100%;
  }
}
</style>
<style lang="less">
.home-container {
  .el-menu {
    .is-active {
      color: #ffffff !important;
      background: rgb(169, 17, 18) !important;
    }
  }
}
</style>
